<%@page contentType="text/html;charset=utf-8" pageEncoding="UTF-8" %>
<%@page import="org.ipo.mm.web.util.pager.MeetingPager, org.ipo.mm.web.util.ConstantManager, java.util.Collection, org.ipo.mm.web.util.security.SecurityManager, java.util.Vector" %>
<%@taglib prefix="l" uri="http://struts.apache.org/tags-logic" %>
<%@taglib prefix="b" uri="http://struts.apache.org/tags-bean" %>
<%@taglib prefix="h" uri="http://struts.apache.org/tags-html"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>




<h1><b:message key="meetings_meetings"/></h1>


<%
            boolean readOnly = false;
            String readOnlyStr = request.getParameter("readOnly");
			if(readOnlyStr==null){
				readOnlyStr="false";
			}

            //if(readOnlyStr!=null){
            //    if(readOnlyStr=="true"){
            //        readOnly = true;
            //        }
            //}
            Collection<Integer> privileges = (Collection<Integer>) request.getSession().getAttribute(ConstantManager.SESSION_USER_PRIVILEGES);
            //request.getParameter("showCreateMeeting").equals("true")
            if (privileges.contains(SecurityManager.CREATE_MEETING_PRIVILEGE)  && readOnlyStr.equals("false")) {%>
            <div id="createMeetingDiv" class="displayNone">
                <h:link styleClass="createNew" action="/protected/dispatch?method=showCreateMeetingForm&rm">
                <b:message key="meetings_createnew"/>
            </h:link>
            </div>

<%}%>



<div id="mDialogs">


	 <l:iterate id="meeting" name="MEETING_SEARCH_RESULTS" scope="request">
	            <div id="m${meeting.id}" class="dialog" title="${meeting.eventName}">

                    <div class="itemDetail" id="m${meeting.id}">
                        <strong><b:message key="gen_action"/></strong><br><br>
                        <span style="border-style:solid;padding:5px;margin-top:15px; border-color: orange">
                             <% if (privileges.contains(SecurityManager.DELETE_MEETING_PRIVILEGE) && readOnlyStr.equals("false")) {%>

                            <c:if test="${(meeting.draft == true) || USER.type == USER_TYPE_ADMIN_PA}">

                                <h:link styleClass="details" action="/protected/dispatch?method=showUpdateMeetingForm&rf=true"
                                        paramId="mid" paramName="meeting" paramProperty="id"><b:message key="gen_update"/>
                                </h:link>


                        </c:if>



                         <% }%>

                            <%

                                        if (privileges.contains(SecurityManager.DELETE_MEETING_PRIVILEGE) && readOnlyStr.equals("false")) {
										%>

                            <h:link styleClass="delete" action="/protected/dispatch?method=deleteMeeting"
                                    paramId="mid" paramName="meeting" paramProperty="id" onclick="return confirm('Are you sure you want to delete this item?/Da li ste sigurni da zelite da izbrisete ovaj entitet?')"
                                    ><b:message key="gen_delete"/></h:link>

                            <%}%>



                            <a href="<%= request.getContextPath()%>/protected/GetMeetingRaport?mid=${meeting.id}" class="print" ><b:message key="gen_print"/></a>

                        </span>

                        <p><strong><b:message key="meetings_organizer"/></strong></p>
                        ${meeting.organizer.firstName} ${meeting.organizer.lastName}
                        <div class="displayNone">
                        <h:link action="/protected/meeting_search?rid=${meeting.organizer.id}" ><b:message key="meetings_meetings_with_person"/></h:link>
                        </div>
                        <p><strong><b:message key="meetings_institution"/></strong></p>
                        ${meeting.organizer.institution.name}
                        <div class="displayNone">
                            <h:link action="/protected/meeting_search?iid=${meeting.organizer.institution.id}" >
                                <b:message key="meetings_meetings_with_institution"/>
                            </h:link>
                        </div>
                        <p><strong><b:message key="meetings_participants"/></strong></p>
                        <table>
                            <tr>
                                <th style="background-color: #F2F2F2; color:#6589AB;"><b:message key="repr_name"/></th>
                                <th style="background-color: #F2F2F2; color:#6589AB;"><b:message key="repr_inst"/></th><!--
                                <th><b:message key="repr_inst_type"/></th>
                                <th><b:message key="repr_inst_family"/></th>
                                <th><b:message key="repr_inst_region"/></th>-->
                            </tr>
                            <l:iterate id="rep" name="meeting" property="representativeCollection">
                                <tr>
                                    <td>
                                        <c:choose>
                                            <c:when test="${rep.user == USER || USER.type == USER_TYPE_ADMIN_PA}">
                                                <h:link action="/protected/dispatch?method=showUpdateReprForm"
                                                        paramId="rid" paramName="rep" paramProperty="id">
                                                    <b:write name="rep" property="firstName"/>

                                                    <b:write name="rep" property="lastName"/>
                                                </h:link>
                                            </c:when>

                                            <c:otherwise>
                                                <b:write name="rep" property="firstName"/>
                                                <b:write name="rep" property="lastName"/>
                                            </c:otherwise>
                                        </c:choose>



                                        <div class="displayNone">
                                            <h:link action="/protected/meeting_search" paramId="rid" paramName="rep" paramProperty="id"><b:message key="meetings_meetings_with_person"/></h:link>
                                        </div>
                                    </td>
                                    <td>
                                        <%

                                                    if (privileges.contains(SecurityManager.EDIT_INSTITUTION_PRIVILEGE)  && readOnlyStr.equals("false")) {%>

                                        <c:choose>
                                            <c:when test="${rep.institution.user == USER || USER.type == USER_TYPE_ADMIN_PA}">
                                                <h:link styleClass="details" action="/protected/dispatch?method=showUpdateInstForm&iid=${rep.institution.id}">
                                                    ${rep.institution.name}
                                                </h:link>
                                            </c:when>

                                            <c:otherwise>
                                                ${rep.institution.name}
                                            </c:otherwise>
                                        </c:choose>


                                        <%}%>

<div class="displayNone">
    <h:link action="/protected/meeting_search?iid=${rep.institution.id}">
        <b:message key="meetings_meetings_with_institution"/></h:link>
</div>
</td>

                                    <!--<td>${rep.institution.type.name}</td>
                                    <td>${rep.institution.family.name}</td>
                                    <td>${rep.institution.region.name}</td>-->
                                </tr>
                            </l:iterate>
                        </table>

                        <p>
                            <strong><b:message key="meetings_minutes"/></strong><br />
                            <textarea cols="100" rows="10" readonly><b:write name="meeting" property="conclusion"/></textarea>
                        </p>
                        <p>
                            <strong><b:message key="meetings_actions"/></strong><br />
                            <%--<textarea cols="100" rows="10" readonly><b:write name="meeting" property="actions"/></textarea>--%>

                        <table width="100%" border="0" >
                            <tr>
                                <th scope="col" style="background-color: #F2F2F2; color:#6589AB;"><b:message key="meetings_action_action"/></th>
                                <th scope="col" style="background-color: #F2F2F2; color:#6589AB;"><b:message key="meetings_action_name"/></th>
                                <th scope="col" style="background-color: #F2F2F2; color:#6589AB;"><b:message key="meetings_action_status"/></th>
                                <th scope="col" style="background-color: #F2F2F2; color:#6589AB;"><b:message key="meetings_action_due_date"/></th>
                            </tr>



                            <l:iterate id="actions" name="meeting" property="meetingActions">

                                <tr >
                                    <td>
                                        <b:write name="actions" property="actionText"/>
                                    </td>
                                    <td>
                                        <strong><b:write name="actions" property="name"/></strong>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${actions.status == 'FINISHED'}">
                                                <b:message key="actions_finished" />
                                            </c:when>

                                            <c:when test="${actions.status == 'PENDING'}">
                                                <b:message key="actions_pending" />
                                            </c:when>

                                        </c:choose>


                                    </td>
                                    <td>
                                        <b:write name="actions" property="dueDate" format="dd/MM/yyyy"/>
                                    </td>
                                </tr>

                            </l:iterate>

                        </table>


                        <p>
                            <strong><b:message key="gen_note"/></strong><br />
                            <textarea cols="100" rows="10" readonly><b:write name="meeting" property="note"/></textarea>

                        </p>

                        <strong><b:message key="meetings_files"/></strong><br />

                        <l:notEmpty name="meeting" property="documentCollection">
                            <l:iterate id="doc" name="meeting" property="documentCollection">
                                <div style="padding-bottom:5px;">
                                    <b:message key="meetings_files_name"/> <b:write name="doc" property="name"/>
                                    <b:message key="meetings_files_note"/> <b:write name="doc" property="note"/>
                                    <a href="doc_download?did=${doc.documentPK.id}&mid=${doc.documentPK.meeting}" class="download">Download <b:write name="doc" property="fileName"/></a><br />
                                </div>
                            </l:iterate>
                        </l:notEmpty>

                        <p>
                            <strong><b:message key="gen_action"/></strong><br><br>
                            <span style="border-style:solid;padding:5px;margin-top:15px; border-color: orange">

                                <% if (privileges.contains(SecurityManager.EDIT_MEETING_PRIVILEGE)  && readOnlyStr.equals("false")) {%>

                                <c:if test="${(meeting.user == USER && meeting.draft == true) || USER.type == USER_TYPE_ADMIN_PA}">
                                    <h:link styleClass="details" action="/protected/dispatch?method=showUpdateMeetingForm&rf=true"
                                            paramId="mid" paramName="meeting" paramProperty="id"><b:message key="gen_update"/>
                                    </h:link>


                                </c:if>



                                <% }%>

                                <%

                                            if (privileges.contains(SecurityManager.DELETE_MEETING_PRIVILEGE)  && readOnlyStr.equals("false")) {%>

                                <h:link styleClass="delete" action="/protected/dispatch?method=deleteMeeting"
                                        paramId="mid" paramName="meeting" paramProperty="id" onclick="return confirm('Are you sure you want to delete this item?/Da li ste sigurni da zelite da izbrisete ovaj entitet?')"
                                        ><b:message key="gen_delete"/></h:link>

                                <%}%>



                                <a href="<%= request.getContextPath()%>/protected/GetMeetingRaport?mid=${meeting.id}" class="print" ><b:message key="gen_print"/></a>

                            </span>
                        </p>
                    </div>

			</div>
			  </l:iterate>



</div>

